Custom Domains: Map our Domain to Load Balancers
We'll cover the following
Creating a DNS record per stage#
Let’s start by adding two new input parameters in our stage.yml
to receive the stage domain and subdomain.
Then, let’s add a resource to create a Route 53 A record that points <subdomain>.<domain>
to the load balancer.
Next, let’s change the stage output to return the URL with our custom domain rather than the load balancer’s default endpoint.
Then we also need to add an input parameter in main.yml
to receive our custom domain name.
And finally, we need to pass our custom domain to the nested stacks.
Line #9 and #20: Passes the domain name to the nested stack.
Line #10 and #21: Passes a stack-specific subdomain to the nested stack.
At this point, let’s add our domain name as an environment variable at the top of deploy-infra.sh
.
Line #1: Replace with your domain name.
And now we can pass our domain to the CloudFormation template.
Line #12: Passes the domain name to main.yml
.
Let’s deploy to see our custom domain in action.
And now have a much more human-friendly endpoint for our two stages. We should also be able to see the A records in our Route 53 hosted zone.
The DNS propagation can take a few minutes. After a while, we should be able to reach our application through our custom domain.
🔍 If the
curl
commands work, but your browser times out trying to connect, it may be trying to upgrade to HTTPS in order to provide better security. You can try from another browser or wait until we enable HTTPS in the next section.
Now we can commit all our changes to checkpoint our progress.
Note: All the code has been already added and we are pushing it on our repository as well.
/
- deploy-infra.sh
In order to get a pictorial view of our developed cloudformation stack so far, below is the design view which shows the resources we created and their relationships.
In the next lesson, we will migrate our endpoint from HTTP to HTTPS.